/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package agents;

import env.Action;
import env.Orientation;
import java.awt.Color;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import next_flag_search.Search;

/**
 *
 * @author user
 */
public class SmartAgent extends Agent {
    static Icon iconNorth=new ImageIcon("images/AgentNorthRed.GIF");
    static Icon iconSouth=new ImageIcon("images/AgentSouthRed.GIF");
    static Icon iconEast=new ImageIcon("images/AgentEastRed.GIF");
    static Icon iconWest=new ImageIcon("images/AgentWestRed.GIF");
    
    private Search search;
    
    public SmartAgent(String name, int row, int col, Orientation orientation, Color color, Search search) {
        super(name, row, col, orientation, color);
        this.search=search;
        search.setAgent(this);
    }
    
    @Override
    public Action getMove() {
        return search.nextAction();
    }

    @Override
    public Icon getIcon() {
        switch(this.getOrientation()) {
            case North: return iconNorth;
            case East: return iconEast;
            case West: return iconWest;
            case South: return iconSouth;
        }
        return null;
    }
    
    @Override
    public void moveFailed() {
        System.out.println(getName()+ " is stuck! replanning...");
        search.rePlan();
//        try {
//                System.in.read();
//            } catch (IOException ex) {
//                Logger.getLogger(SmartAgent.class.getName()).log(Level.SEVERE, null, ex);
//            }
    }

}
